﻿using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml;

namespace MetaDataParser.Helpers;
internal class JsonRichTextBlockBindingHelper
{
    public static string GetText(DependencyObject obj)
    {
        return (string)obj.GetValue(TextProperty);
    }

    public static void SetText(DependencyObject obj, string value)
    {
        obj.SetValue(TextProperty, value);
    }

    // Using a DependencyProperty as the backing store for Text.  
    // This enables animation, styling, binding, etc.
    public static readonly DependencyProperty TextProperty =
           DependencyProperty.RegisterAttached("Text", typeof(string),
           typeof(JsonRichTextBlockBindingHelper), new PropertyMetadata(String.Empty, OnTextChanged));

    private static void OnTextChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
    {
        if (sender is TextControlBoxNS.TextControlBox richTextBlock)
        {
            if (e.NewValue != null)
            {
                richTextBlock.LoadText(e.NewValue?.ToString());
            }
        }
    }
}
